package day1130;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class JDBCUtil {
	private JDBCUtil() {
		
	}
	private static ResourceBundle rb = ResourceBundle.getBundle("jdbc");
	private static String user = rb.getString("user");
	private static String password = rb.getString("password");
	private static String url = rb.getString("url");
	private static String driver = rb.getString("driver");
	public static Connection getConnection() {
		//加载驱动
		Connection conn = null;
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, password);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void close(Connection conn,PreparedStatement ps) {
		try {
			if(conn!=null) {
				conn.close();
				conn = null;
			}
			if(ps!=null) {
				ps.close();
				ps=null;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		System.out.println(JDBCUtil.getConnection());
	}

}
